package cn.tedu.boot11.controller;

import cn.tedu.boot11.entity.User;
import cn.tedu.boot11.utils.DBUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;

@RestController
public class UserController {
    @RequestMapping("/reg")
    public String reg(User user){
        try (Connection con = DBUtils.getConn()){
            String sql = "insert into user values(null,?,?,?)";
            PreparedStatement ps = con.prepareStatement(sql);
            ps.setString(1, user.getUsername());
            ps.setString(2, user.getPassword());
            ps.setString(3, user.getNick());
            ps.executeUpdate();
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return "注册成功";
    }
}
